<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>编辑奖品</title>
    <%@include file="common/include.jsp" %>
    <style type="text/css">
    	.col-lg-8 {
    		    position: absolute;
    			left: 40%;
    			top: 15%;
    			width: 20%;
    	}
    </style>
    
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-lg-8">
            <form id="form" role="form">
                <input id="id" name="id" value="${prize.id}" hidden>
                <div class="form-group">
                    <label for="name">奖品名称</label>
                    <input type="text" class="form-control" id="name" name="name" value="${prize.name}" placeholder="请输入奖品名称">
                </div>
                <div class="form-group">
                    <label for="weight">概率权重</label>
                    <input type="number" class="form-control" id="weight" name="weight" value="${prize.weight}" placeholder="请输入概率权重">
                </div>
                <div class="form-group">
                    <label for="day14">14日限定值</label>
                    <input type="number" class="form-control" id="day14" name="day14" value="${prize.day14}" placeholder="请输入14日限定值">
                </div>
                <div class="form-group">
                    <label for="day15">15日限定值</label>
                    <input type="number" class="form-control" id="day15" name="day15" value="${prize.day15}" placeholder="请输入15日限定值">
                </div>
                <div class="form-group">
                    <label for="day16">16日限定值</label>
                    <input type="number" class="form-control" id="day16" name="day16" value="${prize.day16}" placeholder="请输入16日限定值">
                </div>
                <div class="form-group">
                    <label for="day17">17日限定值</label>
                    <input type="number" class="form-control" id="day17" name="day17" value="${prize.day17}" placeholder="请输入17日限定值">
                </div>
                <div class="form-group">
                    <label for="day18">18日限定值</label>
                    <input type="number" class="form-control" id="day18" name="day18" value="${prize.day18}" placeholder="请输入18日限定值">
                </div>
                <button type="button" onclick="prizeSave()" class="btn btn-default">保存</button>
                <button type="reset"  onclick="prizeReset()" class="btn btn-default">取消</button>
            </form>
        </div>
    </div>
</div>
<script>
   function prizeSave(){
	var id = $("#id").val();
   	var name = $("#name").val();
   	var weight = $("#weight").val();
   	var day14 = $("#day14").val();
   	var day15 = $("#day15").val();
   	var day16 = $("#day16").val();
   	var day17 = $("#day17").val();
   	var day18 = $("#day18").val();
   	var data = {"id":id,"name":name,"weight":weight,"day14":day14,"day15":day15,"day16":day16,"day17":day17,"day18":day18};
       $.ajax({
           type: 'POST',
           url: '${ctx}/prize/saveEdit',
           data:JSON.stringify(data),
           contentType: 'application/json',
           dataType: 'json',
           success: function (data) {
               if (200==data.status) {
               	window.location.href = '${ctx}/prize/listPrize';
               }else{
               	alert(data.msg);
               }
           },
           error: function () {
               alert("出错了,请重试!");
           }
       }); 
   }
   
   function prizeReset() {
	   window.location.href = '${ctx}/prize/listPrize';
	}
</script>
</body>
</html>